import { boot } from 'quasar/wrappers';
import { useAppStore } from 'src/stores/app-store';

const loginRoutesPath = ['/', '/phoneLogin', '/home'];
// 拦截白名单
const whiteList: string[] = [
  '/down',
  '/feedback',
  '/webview',
  '/evaluate',
  '/evaluateAuth',
  '/approve',
  '/mechanismUrl',
  '/mechanism',
  '/waitPage',
  '/wxfollow',
  '/prodJump',
];
const defaultRoutePath = '/down';
export default boot(({ router }) => {
  router.beforeEach((to, from, next) => {
    const appStore = useAppStore();

    if (whiteList.includes(to.path)) {
      next();
    } else {
      if (appStore.token) {
        next();
        // loginRoutesPath.includes(to.path) ? next({ path: defaultRoutePath, query: from.query }) : next();
      } else {
        // 没有token进登录页面
        if (loginRoutesPath.includes(to.path)) {
          next();
        } else {
          next({ path: loginRoutesPath[0], query: from.query });
        }
      }
    }
  });
});
